#region Using directives

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.IO;

using FighterChessEngine.FC_Board;
using FighterChessSkin.FC_Board;

#endregion

namespace FighterChess
{
    /// <summary>
    /// Summary description for frmBeginGame.
    /// </summary>
    public class frmBeginGame : System.Windows.Forms.Form
    {
        private Button btnNewGame;
        private Button btnLoad;
        private Button btnQuit;
        private PictureBox pictureBox1;

        public frmBeginGame()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmBeginGame));
            this.btnNewGame = new System.Windows.Forms.Button();
            this.btnLoad = new System.Windows.Forms.Button();
            this.btnQuit = new System.Windows.Forms.Button();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            // 
            // btnNewGame
            // 
            this.btnNewGame.BackColor = System.Drawing.Color.Transparent;
            this.btnNewGame.Location = new System.Drawing.Point(151, 204);
            this.btnNewGame.Size = new System.Drawing.Size(86, 25);
            this.btnNewGame.Text = "New game";
            this.btnNewGame.Click += new System.EventHandler(this.btnNewGame_Click);
            // 
            // btnLoad
            // 
            this.btnLoad.BackColor = System.Drawing.Color.Transparent;
            this.btnLoad.Enabled = false;
            this.btnLoad.Location = new System.Drawing.Point(151, 235);
            this.btnLoad.Size = new System.Drawing.Size(86, 23);
            this.btnLoad.Text = "Load";
            this.btnLoad.Click += new System.EventHandler(this.btnLoad_Click);
            // 
            // btnQuit
            // 
            this.btnQuit.BackColor = System.Drawing.Color.Transparent;
            this.btnQuit.Location = new System.Drawing.Point(151, 264);
            this.btnQuit.Size = new System.Drawing.Size(86, 21);
            this.btnQuit.Text = "Quit";
            this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click);
            // 
            // pictureBox1
            // 
            this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
            this.pictureBox1.Location = new System.Drawing.Point(0, 0);
            this.pictureBox1.Size = new System.Drawing.Size(240, 294);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
            // 
            // frmBeginGame
            // 
            this.ClientSize = new System.Drawing.Size(240, 294);
            this.Controls.Add(this.btnQuit);
            this.Controls.Add(this.btnLoad);
            this.Controls.Add(this.btnNewGame);
            this.Controls.Add(this.pictureBox1);
            this.MinimizeBox = false;
            this.Text = "Fighter Chess";
            this.Load += new System.EventHandler(this.frmBeginGame_Load);

        }

        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            Application.Run(new frmBeginGame());
        }

        private readonly string appDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
        private readonly string saveDir = "Save";
        private readonly string saveFile = "save.data";
        private static Form instance;

        public static Form Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new frmBeginGame();
                }

                return instance;
            }
        }

        private void btnQuit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnNewGame_Click(object sender, EventArgs e)
        {   
            frmStart frm = new frmStart();
            frm.Show();
            this.Hide();
            this.pictureBox1.Image = null;
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            string filename = appDir + "\\" + saveDir + "\\" + saveFile;
            Board board = new Board(filename);
            frmMain frm = new frmMain(board);
            frm.Show();
            this.Hide();
            this.pictureBox1.Image = null;
        }

        private void frmBeginGame_Load(object sender, EventArgs e)
        {
            if (!File.Exists(appDir + "\\" + saveDir + "\\" + saveFile))
                btnLoad.Enabled = false;
            else
                btnLoad.Enabled = true;
        }
    }
}
